import QtQuick
import QtQuick3D
import QtQuick.Timeline

import Utils
import QtQuickAnimMontage
import Quick3DAssets.CharacterAnimation

Node{
    id:root
    property alias movement:aniController.movement

    property alias target:montage.target
    property alias handled:aniController.handled

    IdHacker{
        id:idHacker
        target: montage.target
        property Node rightShoulder

    }

    AnimMontage{//将混合后的动画输出给目标
        id:montage
        running:true
        source: animRoot
    }

    //动画混合树
    PoseBlend{//根动画
        id:animRoot

        BasePose{//基本姿态,PoseBlend的第一个姿态必须是基本姿态
            id:standardPose
            source:walk
        }

        Anim{
            id:standTrack
            Behavior on Blend.alpha{
                NumberAnimation{
                    duration: 250
                }
            }
            Blend.alpha:aniController.speed === 0
            source: stand
            duration: 3000
        }

        Anim{
            id:walkTrack
            source:walk

            Behavior on Blend.alpha{
                NumberAnimation{
                    duration: 250
                }
            }
            Blend.alpha:aniController.speed > 0?1.0:0//在速度不为0时启用走路动画
        }

        Anim{
            id:handleTrack
            source:handle
            duration: 3000

            Blend.alpha:handled?1.0:0//当拿起物品时播放拿起动画
            Blend.filterNode: idHacker.rightShoulder//该动画仅右肩膀有效
        }

    }

    Node{
        id:animationTracks
        //动画源
        Walk{
            id:walk
        }

        Stand{
            id:stand
        }

        Handle{
            id:handle
        }
    }


        Node{
            //动画控制器
            id:aniController

            //当前角色的移动方向
            property vector3d movement
            property real speed:movement.length()
            property bool handled:false//当前是否拿着东西

            Binding{
                target: walkTrack
                property:"duration"

                property real baseDuraiton:300//原始动画的基本时常
                property real baseSpeed:400//与基本时常匹配的移动速度
                property real outDuration:{//速度因子
                    let ret = baseDuraiton
                    if(aniController.speed !== 0)
                    {
                        ret = (baseSpeed / aniController.speed) * baseDuraiton
                    }
                    return ret
                }

                value:outDuration
            }

        }

        Node {
            id: __materialLibrary__
        }

}
